const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        auth_value:1,
        up_img:'up_person.png',
        agree:0,
        auth_type:[
            {value: 1, name: '车辆问题',checked:1},
            {value: 2, name: '功能建议',checked:0},
            {value: 3, name: '其他问题',checked:0},
          
        ],
        card_type:[
            {value: 1, name: '身份证'},
            {value: 2, name: '营业执照'},
        ],
        type:0,
        content:0,
        min:5,//最少字数
        max: 300, //最多字数 (根据自己需求改变) 
    
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that=this;
        
        wx.showShareMenu({
            menus: ['shareAppMessage', 'shareTimeline'],
            success(res) {
              console.log(res)
            },
            fail(e) {
              console.log(e)
            }
          })             
          var deviceInfo = wx.getDeviceInfo();
          console.log(deviceInfo)
          let d = app.globalData;
          var open=wx.getStorageSync('open');  
          this.setData({
              //id:id,
              open:open,
              width:d.windowWidth,
              height:d.windowHeight,
              statusBarHeight:d.statusBarHeight,
              navHeight:d.navHeight,
              marginTop:d.navTitleTop,
              bottom:d.bottom,
              domain:d.domain,
              imgUrl:d.imgUrl,
              platform:deviceInfo.platform
          })
    },
   selectType(e){
    console.log(e);
        var type = e.currentTarget.dataset.index;
        this.setData({
            type:type
        })
    
   },
    goBack(){
        wx.navigateBack();
      },
      goto(e){
        console.log(e);
        var url=e.currentTarget.dataset.url;
        console.log(url);
        var index=e.currentTarget.dataset.index;
        app.goto(url,index)
      // console.log(url);
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
      let that=this;
    
      var open=wx.getStorageSync('open');
        if(open.user_id==0){

            app.showModal('请先绑定手机号','bind','#')
            return ;
        }
      console.log(open);
      var auth = open.auth;     
        wx.request({
            url: app.globalData.domain+'/wechat/auth/getIndex',
            data:{user_id:open.user_id,open_id:open.id,from:1},
            success:function(res){
              console.log(res);          
                var data=res.data;
                console.log(data)
                  that.setData({
                    partner:data.partner
                   })
              
        
            }
          })
         
     
    },
    goBack(){
        wx.navigateBack();
      },

 
  //字数限制  
  inputs: function (e) {
    // 获取输入框的内容
    var value = e.detail.value;
    // 获取输入框内容的长度
    var len = parseInt(value.length);
 
    //最少字数限制


 
    //最多字数限制
    if(len > this.data.max) return;
        // 当输入框内容的长度大于最大长度限制（max)时，终止setData()的执行
        this.setData({
           currentWordNumber: len, //当前字数 
           content:value 
        });


  },

    goto:function(e){
        console.log(e);
        var url = e.currentTarget.dataset.url;
        var index = e.currentTarget.dataset.index;
        app.goto(url,index)
    },
    uploadCard:function(e){ 
        let that=this;
        //let imageType='idcard';
        let d = e.currentTarget.dataset;
        let imageType = d.type;

        wx.chooseMedia({
          count: 1,
          mediaType: ['image'],
          sizeType:["compressed"],
          sourceType:["camera","album"],
          success(res){
              console.log(res);
            let tempFilePaths=res.tempFiles[0].tempFilePath;
            that.upload(imageType,tempFilePaths)
          }
        })
        
      },
      upload:function(imageType,path){
        wx.showToast({
          icon:"loading",
          title: '正在上传',
        })
        let that = this;        
      var timestamp=new Date().getTime(); 
      var partner = this.data.partner;
      var domain = this.data.domain;
      console.log(path)

        wx.uploadFile({
         filePath:path ,
          name: 'file',
          url: app.globalData.domain+'/wechat/feedback/upload',
          formData:{
            imageType:imageType,
    
            },
            header: { 
              'content-type':'application/x-www-form-urlencoded'       
             },       
          success(res){
            console.log(res);
            var data=JSON.parse(res.data);
           console.log(data);
            if(data.error==0){  
                that.setData({
                    upload:1,
                    imgs:data.path
                })            
          
       
            }
          }
      
        })
      },
      feedback:function(){
        let that = this; 
        let data=this.data;
        if(data.type == 0 ){
            app.showModal('请选择意见类型');
            return ;
        }
        if(data.content == 0 ){
            app.showModal('请填写意见或者建议');
            return ;
        }
        console.log('feedback');
        wx.request({
            url: app.globalData.domain+'/wechat/feedback/feedback',
            data:{content:data.content,img:data.imgs,user_id:data.open.user_id,open_id:data.open.id,type:data.type},
            success(res){
                console.log(res);
                var data=res.data;
                if(data.code==200){
               
                    wx.showToast({
                      title: data.msg,
                    })
                    wx.navigateBack();
                }
            }
        }) 
      },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})